package com.delos.rbac.controller;

import com.delos.rbac.context.RequestHolder;
import com.delos.rbac.security.TokenAuthentication;
import com.delos.rbac.vo.UserRoleVO;
import com.delos.rbac.vo.UserVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 测试Controller
 *
 * @author zouyaowen
 * @date 2020-06-21
 */
@RestController
@Slf4j
@RequestMapping("/test")
public class TestController {

    @GetMapping("/getData")
    public void getData() {
        TokenAuthentication tokenAuthentication = (TokenAuthentication) SecurityContextHolder.getContext().getAuthentication();
        String name = tokenAuthentication.getName();
        Long userId = tokenAuthentication.getUserId();
        System.out.println("authentication isAuthenticated" + name + userId);
        log.info("getData 请求——————————————————-");
    }

    @PostMapping("/postData")
    public void postData() {
        log.info("postData 请求——————————————————-");
        UserVO userInfo = RequestHolder.getUserInfo();
        System.out.println(userInfo);
    }
}
